<?php

namespace common\models\kaoguobao;

use Yii;
use common\models\BaseModels;
use yii\behaviors\TimestampBehavior;

class Bonus extends BaseModels
{
    const BONUS_TYPE_CASH       = 0;
    const BONUS_TYPE_BROLERAGE  = 1;
    const BONUS_STATE_UNRECEIVE = 0;
    const BONUS_STATE_RECEIVE   = 1;
    const BONUS_STATE_OVER_TIME = -1;
    const TYPE_IELTS            = 0;
    const TYPE_TOEFL            = 1;
    const TYPE_CET4             = 2;
    const TYPE_CET6             = 3;

    //红包类型
    public static $bonusType = [
        self::BONUS_TYPE_CASH       => "返现",
        self::BONUS_TYPE_BROLERAGE  => "返佣",
    ];
    //红包状态
    public static $bonusState = [
        self::BONUS_STATE_UNRECEIVE => "未领取",
        self::BONUS_STATE_RECEIVE   => "已领取",
        self::BONUS_STATE_OVER_TIME => "超时",
    ];
    //保障项目
    public static $typeName = [
        self::TYPE_IELTS    => "雅思",
        self::TYPE_TOEFL    => "托福",
        self::TYPE_CET4     => "四级",
        self::TYPE_CET6     => "六级",
    ];

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%bonus}}';
    }

    /**
     * 切换数据库(测试环境)
     */
    public static function getDb(){
        return Yii::$app->get('db_kgb');
    }

    /**
     * 给数据库的处理进行时间的操作
     */
    public function behaviors() {
        return [
            TimestampBehavior::className(),
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [[  'id',
                'user_id',
                'order_num',
                'is_valid',
                'amount',
                'key',
                'type',
                'bonus_type',
                'bonus_state',
                'remarks',
                'created_at',
                'updated_at',
            ], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id'            => Yii::t('app_table', 'ID'),
            'user_id'       => Yii::t('app_table', '用户ID'),
            'order_num'     => Yii::t('app_table', '订单号'),
            'is_valid'      => Yii::t('app_table', '状态'),
            'amount'        => Yii::t('app_table', '红包金额'),
            'key'           => Yii::t('app_table', '键值，区分产品'),
            'type'          => Yii::t('app_table', '保障项目'),
            'bonus_type'    => Yii::t('app_table', '红包类型'),
            'bonus_state'   => Yii::t('app_table', '红包状态'),
            'remarks'       => Yii::t('app_table', '备注'),
            'created_at'    => Yii::t('app_table', '创建时间'),
            'updated_at'    => Yii::t('app_table', '修改时间'),
        ];
    }
}